﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Tisonet.Dobrak.Client.WP8.App_Start;
using Tisonet.Dobrak.Client.WP8.ViewModels;

namespace Tisonet.Dobrak.Client.WP8.Views
{
    public partial class MovieDetailView : PhoneApplicationPage
    {
        private MovieViewModel _viewModel;

        public MovieViewModel ViewModel
        {
            get
            {
                if (_viewModel == null)
                {
                    _viewModel = IoCContainter.Get<MovieViewModel>();
                }

                return _viewModel;
            }
        }

        public MovieDetailView()
        {
            InitializeComponent();

            DataContext =  ViewModel;
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string projectionId; 
            
            if (NavigationContext.QueryString.TryGetValue("ID", out projectionId))
            {
                ShowProjectionDetail(projectionId);
            }
        }

        private void ShowProjectionDetail(string projectionID)
        {
            if (!ViewModel.IsDataLoaded)
            {
                ViewModel.LoadData(projectionID);
            }
        }
    }
}